package com.fr.report.core;

import java.io.Serializable;
import java.util.Arrays;

public class DynamicValueList
  implements Cloneable, Serializable
{
  private static final long serialVersionUID = 1L;
  private int[] elementInts;
  private int size;
  private int defaultValue;

  public DynamicValueList(int paramInt)
  {
    this(paramInt, 10);
  }

  public DynamicValueList(int paramInt1, int paramInt2)
  {
    this.defaultValue = 1;
    this.elementInts = new int[paramInt2];
    Arrays.fill(this.elementInts, paramInt1);
    this.size = this.elementInts.length;
    this.defaultValue = paramInt1;
  }

  public int getDefaultValue()
  {
    return this.defaultValue;
  }

  public void setDefaultValue(int paramInt)
  {
    this.defaultValue = paramInt;
  }

  public int size()
  {
    return this.size;
  }

  public int get(int paramInt)
  {
    if ((paramInt < 0) || (paramInt >= this.size))
      return this.defaultValue;
    return this.elementInts[paramInt];
  }

  public void set(int paramInt1, int paramInt2)
  {
    if (paramInt1 < 0)
      return;
    if (paramInt1 >= this.size)
    {
      if (paramInt2 == this.defaultValue)
        return;
      ensureCapacity(paramInt1 + 1);
    }
    this.elementInts[paramInt1] = paramInt2;
    if (paramInt1 >= this.size)
      this.size = (paramInt1 + 1);
  }

  public void insert(int paramInt)
  {
    insert(paramInt, 1);
  }

  public void insert(int paramInt1, int paramInt2)
  {
    if ((paramInt1 < 0) || (paramInt2 <= 0) || (paramInt1 >= this.size))
      return;
    ensureCapacity(this.size + paramInt2);
    System.arraycopy(this.elementInts, paramInt1, this.elementInts, paramInt1 + paramInt2, this.size - paramInt1);
    Arrays.fill(this.elementInts, paramInt1, paramInt1 + paramInt2, this.defaultValue);
    this.size += paramInt2;
  }

  public int remove(int paramInt)
  {
    if ((paramInt < 0) || (paramInt >= this.size))
      return this.defaultValue;
    int i = this.elementInts[paramInt];
    int j = this.size - paramInt - 1;
    if (j > 0)
      System.arraycopy(this.elementInts, paramInt + 1, this.elementInts, paramInt, j);
    this.elementInts[(--this.size)] = this.defaultValue;
    return i;
  }

  public void reset()
  {
    Arrays.fill(this.elementInts, this.defaultValue);
    this.size = 0;
  }

  public int getRangeValueFromZero(int paramInt)
  {
    return getRangeValue(0, paramInt);
  }

  public int getRangeValue(int paramInt1, int paramInt2)
  {
    int i = 0;
    int j = Math.min(paramInt1, paramInt2);
    int k = Math.max(paramInt1, paramInt2);
    j = Math.max(0, j);
    int l = j;
    int i1 = Math.min(k, this.elementInts.length);
    while (l < i1)
    {
      i += this.elementInts[l];
      ++l;
    }
    if (k > this.elementInts.length)
      i += (k - Math.max(this.elementInts.length, j)) * this.defaultValue;
    return ((paramInt1 <= paramInt2) ? i : -i);
  }

  public int getValueIndex(int paramInt)
  {
    return getValueIndex(paramInt, 0);
  }

  public int getValueIndex(int paramInt1, int paramInt2)
  {
    int i = 0;
    int j = paramInt2;
    while (true)
    {
      i += get(j);
      if (i > paramInt1)
        return j;
      ++j;
    }
  }

  private void ensureCapacity(int paramInt)
  {
    int i = this.elementInts.length;
    if (paramInt > i)
    {
      int[] arrayOfInt = this.elementInts;
      int j = i * 3 / 2 + 1;
      if (j < paramInt)
        j = paramInt;
      this.elementInts = new int[j];
      System.arraycopy(arrayOfInt, 0, this.elementInts, 0, arrayOfInt.length);
      Arrays.fill(this.elementInts, arrayOfInt.length, this.elementInts.length, this.defaultValue);
    }
  }

  public Object clone()
    throws CloneNotSupportedException
  {
    DynamicValueList localDynamicValueList = (DynamicValueList)super.clone();
    localDynamicValueList.elementInts = ((int[])this.elementInts.clone());
    return localDynamicValueList;
  }
}